package com.nervenets.general.exception;

import com.nervenets.general.enumeration.MessageImportanceLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.http.HttpStatus;

@EqualsAndHashCode(callSuper = true)
@Data
public class LogicException extends RuntimeException {
    private int code;
    private MessageImportanceLevel level;

    public LogicException(int code, String message, MessageImportanceLevel level, Exception e) {
        super(message, e);
        this.code = code;
        this.level = level;
    }

    public LogicException(int code, String message, MessageImportanceLevel level) {
        this(code, message, level, null);
    }

    public LogicException(int code, String message) {
        this(code, message, MessageImportanceLevel.normal, null);
    }

    public LogicException(String message) {
        this(HttpStatus.BAD_REQUEST.value(), message, MessageImportanceLevel.normal, null);
    }

    public LogicException(int code) {
        this(code, null, MessageImportanceLevel.normal, null);
    }

    public LogicException(String message, Exception e) {
        this(HttpStatus.BAD_REQUEST.value(), message, MessageImportanceLevel.normal, e);
    }

    public LogicException(String message, MessageImportanceLevel level) {
        this(HttpStatus.BAD_REQUEST.value(), message, level, null);
    }

    public LogicException(String format, Object... args) {
        this(HttpStatus.BAD_REQUEST.value(), String.format(format, args), MessageImportanceLevel.normal, null);
    }

    public LogicException(int code, String formatMessage, Object... args) {
        this(code, String.format(formatMessage, args), MessageImportanceLevel.normal, null);
    }

    public LogicException(int code, MessageImportanceLevel level, String formatMessage, Object... args) {
        this(code, String.format(formatMessage, args), level, null);
    }
}
